import { req_hall_special,req_special_sort,req_special_list } from "@/api";

const state={
    h_special:{},
    special_sort:{},
    special_info:{},
    special_info_list:{},
};
const getters={
};
const mutations={
    H_SPECIAL(state,data){
      for (var i in data.list) {
        data.list[i].imgurl = data.list[i].imgurl.replace('/{size}/', '/')
    }
      state.h_special=data
    },
    SPECIAL_SORT(state,data){
      //删除第一条没用的信息
      var a=data.info.filter(((j)=>j!==data.info[0]))
      //处理图片路径问题
      for(let i in a){
        a[i].icon=a[i].icon.replace('/{size}/','/')
      }
      state.special_sort=a
    },
    SPECIAL_LIST(state,data){
      state.special_info=data.info[0]
      // console.log(data.info)
    },
    SPECIAL_LIST_INFO(state,data){
      for(var i in data.info){
        data.info[i].imgurl=data.info[i].imgurl.replace('/{size}/', '/')
      }
      state.special_info_list=data
    }
};
const actions={
  //首页热门歌单
  async req_h_special({commit}){
    let result=await req_hall_special()
    if(result.status==1){
      commit('H_SPECIAL',result.data)
    }else{
      return Promise.reject(new Error('faile'))
    }
  },
  //歌单分类详情
  async special_sort({commit},pid){
    let result=await req_special_sort(pid)
    if(result.status==1){
      if(pid==0){
        commit('SPECIAL_SORT',result.data)
      }else{
        commit('SPECIAL_LIST',result.data)
      }
      
    }else{
      return Promise.reject(new Error('faile'))
    }
  },
  //歌单列表
  async special_list({commit},{tagid,id}){
    let result=await req_special_list(tagid,id)
    if(result.status==1){
        commit('SPECIAL_LIST_INFO',result.data)  
    }else{
      return Promise.reject(new Error('faile'))
    }
  },
};
const modules={

};

export default{
    state,
    getters,
    mutations,
    actions,
    modules
  }